{% extends 'base.html' %}
{% load mytags %}
{% block content %}
{% include 'nav_cat_bar.html' %}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-10">
            <div class="ibox float-e-margins">

                <div class="ibox-title">
                    <h5> 查看项目详情</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">
                    <form id="asset_form">
                        {% if perms.account.perm_can_add_project %}
                        <div class="col-sm-1 pull-left">
                            <a href="{% url 'project_add' %}" class="btn btn-sm btn-primary "> 添加项目 </a>
                        </div>
                        {% endif %}

                        <div class="col-sm-4 pull-right">
                             <div class="input-group inline-group">
                                <input type="text" class="form-control m-b input-sm" id="search_input" name="keyword" value="{{ keyword }}" placeholder="Search">
                                <input type="text" style="display: none">
                                <div class="input-group-btn">
                                    <button id='search_btn' href="{% url 'project_list' %}?search=true" type="button" class="btn btn-sm btn-primary search-btn"  onclick="change_info()">
                                        - 搜索 -
                                    </button>
                                </div>
                            </div>
                        </div>
                        <table class="table table-striped table-bordered table-hover " id="editable" >
                            <thead>
                                <tr>
                                    <th class="text-center">#</th>
                                    <th class="text-center">项目名称/应用服务器IP</th>
                                    <th class="text-center">开发语言</th>
                                    <th class="text-center">发布环境</th>
                                    <th class="text-center">上次发布时间</th>
                                    <th class="text-center">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            {% for project_name in project_name_list %}
                                <tr class="gradeX" style="font-size:18px;">
                                    <td class="text-center">{{ forloop.counter }}</td>
                                    <td class="text-center">{{ project_name }}</td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                </tr>
                                {% for project in project_list %}
                                    {% if project.name == project_name %}
                                    <tr class="gradeX">
                                        <td></td>
                                        <td class="text-center">
                                            <a href="{% url 'project_detail' %}?id={{ project.id }}">
                                                {% for host in project.host|my_split:'|' %}
                                                    <p>{{ host }}</p>
                                                {% endfor %}
                                            </a>
                                        </td>
                                        <td class="text-center">
                                            {{ project.language_type|get_language_type_name }}
                                        </td>
                                        <td class="text-center">
                                            {{ project.env|get_mvnenv_name }}
                                        </td>
                                        <td class="text-center">{{ project.last_deploy_time|none2null }}</td>
                                        <td class="text-center">
                                            {% if perms.account.perm_can_edit_project %}
                                            <a href="{% url 'project_edit' %}?id={{ project.id }}" class="btn btn-xs btn-info">编辑</a>
                                            {% endif %}
                                            {% if perms.account.perm_can_del_project %}
                                                <a value="{{ project.id }}" class="btn btn-xs btn-danger project_del">删除</a>
                                            {% endif %}
                                        </td>
                                    </tr>
                                    {% endif %}
                                {% endfor %}
                            {% endfor %}
                            </tbody>
                        </table>
{#                        <div class="row">#}
{#                            <div class="col-sm-6">#}
{#                                <div class="dataTables_info" id="editable_info" role="status" aria-live="polite">#}
{#                                    Showing {{ projects.start_index }} to {{ projects.end_index }} of {{ p.count }} entries#}
{#                                </div>#}
{#                            </div>#}
{#                            {% include 'paginator.html' %}#}
{#                        </div>#}
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block self_footer_js %}
    <script>
    $(document).ready(function() {
        $('.project_del').click(function () {
            var url = '{% url 'project_del' %}?id=' + $(this).attr('value');
            if (confirm("确定删除?")) {
                $.ajax({
                    type: 'GET',
                    url: url,
                    data: {},
                    success: function (data) {
                        if (data == 'error' || data == '' || data == undefined) {
                            layer.alert('提交出错，联系管理员！')
                        }
                        parent.location.reload();
                    }
                });
            }
        });
    });

    function change_info(){
        var args = $("#asset_form").serialize();
        window.location = "{% url 'project_list' %}?" + args
    }
    </script>
{% endblock %}

